/*
 * Copyright (c) 2017,安徽皖通科技股份有限公司 All rights reserved.
 */

package com.wttech.dzzf.process.service.migrate;

import com.wtkj.exception.BusinessException;
import com.wtkj.vo.dzzf.base.kfwd.Account;
import com.wtkj.vo.dzzf.base.kfwd.CompanyInfo;
import com.wtkj.vo.dzzf.base.kfwd.FundAccount;
import com.wtkj.vo.dzzf.base.kfwd.UserInfo;
import com.wttech.dzzf.process.constant.UserConstants;
import com.wttech.dzzf.process.dao.ImportHisDataDao;
import com.wttech.dzzf.process.service.base.BaseInfoService;
import com.wttech.dzzf.process.util.BusinessUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 资金账户信息处理
 *
 * @author MaShibo
 * @date 2017/12/10.
 */
@Service("fundAccountHisDataProcess")
public class FundAccountProcessService {

	@Resource
	private ImportHisDataDao importHisDataDao;

	@Resource(name = "accoutHisDataProcess")
	private AccountProcessService accountProcessService;

	@Resource
	private BaseInfoService baseInfoService;

	@Transactional(rollbackFor = Exception.class)
	public void process(FundAccount fundAccount) {
		String fundAccountId = fundAccount.getFundAccountId();
		Integer accountType = fundAccount.getAccountType();

		String fundAccountNo = baseInfoService.generateAccountNo(accountType);

		importHisDataDao.updateFundAccountNo(fundAccountId, fundAccountNo);

		List<Account> accounts = importHisDataDao.queryAccountsByFundAccountId(fundAccountId);
		accounts.forEach(account -> accountProcessService.process(account, fundAccount));
	}

}
